#
#
#   NRK plugin for XBMC Media center
#
# Copyright (C) 2009 Victor Vikene  contact: z0py3r@hotmail.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
#

import sys

__settings__ = sys.modules[ "__main__" ].__settings__
__language__ = sys.modules[ "__main__" ].__language__


import os
import api_nrk as nrk
import xbmc
from utils import Key, Plugin, Log, State, PluginError
from xbmcgui import ListItem
from xbmcplugin import addDirectoryItem, endOfDirectory, getSetting

Log.notice( "addon.NRK.load ::  '%s'" % __name__ )

plugin = Plugin()
lang = plugin.language
key = Key( sys.argv[2] )

class Main:
    
    def add(self, label, prefix, type, id=None, img='', icon='', isdir=True, commands=None):
    
        if img != '':
            img = plugin.image(img)
            
        url = Key.build_url(prefix, type=type, id=id)
        li  = ListItem(label, iconImage=icon, thumbnailImage=img)
        if commands:
            li.addContextMenuItems( commands, True )
        ok  = addDirectoryItem(plugin.hndl, url=url, listitem=li, isFolder=isdir)
        
        return ok
        
        
        
    def __init__(self):
        if key.type == 'other':
            self.add(lang(30257),  'nrkbeta',    'feed',     img='ico_nrkbeta.png')
        elif key.type == 'podcastgroup':
            self.add(lang(30260),  'podcast',    'video',    img='ico_podcast.png')
            self.add(lang(30259),  'podcast',    'sound',    img='ico_podcast.png')

        endOfDirectory(plugin.hndl)